<script setup lang="ts">
import { get, loadFile, message, post } from '@/utils'
import ConfigModal from './components/ConfigModal.vue'
import useModal from '@/hooks/useModal'
import { BtnPermission } from '@/enum/permission'
import useTable from '@/hooks/useTable'
const { store } = useModal()
const { formatColumns } = useTable()
const searchQuery = reactive({})
const formRef = ref()
const actionRef = ref()

const pagination = {
  showPageSize: true,
  pageSize: 20,
}
const request = (params: any, sort: any, filters: any): Promise<any> => {
  return new Promise((resolve, reject) => {
    const query = { ...params, size: params.pageSize }
    Reflect.deleteProperty(query, 'pageSize')
    get(
      {
        url: '/server-system/admin/config/page',
        data: query,
      },
      ({ data, code }) => {
        resolve({
          data: data.records,
          total: data.total,
          success: code == 200,
        })
      }
    )
  })
}
const columns = formatColumns([
  {
    title: '标题',
    dataIndex: 'configName',
    hideInSearch: false,
  },
  {
    title: '配置键名',
    dataIndex: 'configKey',
  },
  // {
  //   title: '配置键值',
  //   dataIndex: 'configValue'
  // },
  {
    title: '更新时间',
    dataIndex: 'updateTime',
  },
  {
    title: '操作',
    dataIndex: 'operations',
    width: 300,
    btnList: [
      {
        name: '配置',
        permission: BtnPermission.编辑,
        handle: ({ record }) => store.handleShow(record, true),
      },
    ],
  },
])
</script>

<template>
  <div class="page">
    <ProTable :columns="columns" :request="request" row-key="id" :form-ref="ref => (formRef = ref)" :pagination="pagination" header-title="" :scroll="{ x: 1000 }" column-resizable :params="searchQuery" :bordered="{ cell: true }" :action-ref="ref => (actionRef = ref)">
      <template #option-render="{ dom, reset }">
        <component :is="dom[1]" />
        <component :is="dom[0]" />
      </template>
    </ProTable>
    <ConfigModal v-if="store.show" :edit="store.edit" width="800px" v-model:show="store.show" :id="store.id" @confirm="actionRef.reload" />
  </div>
</template>
